/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com;

import java.awt.*;
import javax.swing.JPanel;

/**
 *
 * @author alrz
 */
public class Figure extends JPanel
{
    private Dimension size;
    private boolean pressed;
    private int up;
    private int down;
    private int left;
    private int right;

    public Figure( int up, int down, int left, int right)
    {
        this.up = up;
        this.down = down;
        this.left = left;
        this.right = right;
        
    }

    public int getDown()
    {
        return down;
    }

    public void setDown(int down)
    {
        this.down = down;
    }

    public int getLeft() {
        return left;
    }

    public void setLeft(int left) {
        this.left = left;
    }

    public int getRight() {
        return right;
    }

    public void setRight(int right) {
        this.right = right;
    }

    public int getUp() {
        return up;
    }

    public void setUp(int up) {
        this.up = up;
    } 
    
    @Override
    public void paint(Graphics g)
    {
        //Up
        super.paintComponent(g);
        
        this.designPolygon(g, up, new Point(0,0), new Point(this.getWidth(),0), new Point(this.getWidth()/2,this.getWidth()/2));
        this.drawIcon(g, up, new Point((int)(this.getX()/4),10));
        //Left
        this.designPolygon(g, up, new Point(0,0), new Point(0,this.getHeight()), new Point(this.getWidth()/2,this.getWidth()/2));
        
        //Down
        this.designPolygon(g, up, new Point(0,this.getHeight()), new Point(this.getWidth(),this.getHeight()), new Point(this.getWidth()/2,this.getWidth()/2));
        
        //Right
        this.designPolygon(g, up, new Point(this.getWidth(),0), new Point(this.getWidth(),this.getHeight()), new Point(this.getWidth()/2,this.getWidth()/2));
    }
    
    @Override
    public void update(Graphics g)
    {
        paint(g);
    }
    
    public void designPolygon(Graphics g, int value, Point p1, Point p2, Point p3)
    {
        Polygon p = new Polygon();
        p.addPoint(p1.x, p1.y);
        p.addPoint(p2.x, p2.y);
        p.addPoint(p3.x, p3.y);
        g.setColor(getColor(value));
        g.fillPolygon(p);
    }
    public void drawIcon(Graphics g, int value, Point p)
    {
        g.drawImage(Icons.getIconNumber(value), p.x, p.y, this);
    }
    public Color getColor(int value)
    {
        if(value == 1)
        {            
            return Color.PINK;
        }
        if(value == 2)
        {
            return Color.RED;
        }
        if(value == 3)
        {
            return Color.ORANGE;
        }
        if(value == 4)
        {
            return Color.YELLOW;
        }
        if(value == 5)
        {
            return Color.GREEN;
        }
        if(value == 6)
        {
            return Color.BLUE;
        }
        if(value == 7)
        {
            return Color.MAGENTA;
        }
        if(value == 8)
        {
            return Color.GRAY;
        }
        if(value == 9)
        {
            return Color.WHITE;
        }
        
        return Color.BLACK;
    }
}
